package cn.e4j.modular.crm.controller;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.shiro.ShiroKit;
import cn.e4j.core.shiro.ShiroUser;
import cn.e4j.modular.crm.entity.GwglT;
import cn.e4j.modular.crm.service.GwglTService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDate;
import java.util.List;

/**
 * 项目费用
 */
@Controller
@RequestMapping("/crm/gwgi006")
public class Gwgi006Controller extends BaseController {

    @Autowired
    GwglTService gwglTService;

    /**
     * 跳转至招标信息维护主界面
     *
     * @return
     */
    @RequiresPermissions("crm:gwgi006:init")
    @RequestMapping(value = {"", "/init"})
    public String index() {
        return "/pc/crm/gwgi006.html";
    }


    @RequiresPermissions("crm:gwgi006:init")
    @RequestMapping("/getHeadList")
    @ResponseBody
    public ResponseData getHeadList(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        Page<Object> page = dtoWapper.getPage();
        List<Dto> list = gwglTService.getHeadList(page,inDto);
        return new PageReData(page, list);
    }


    @RequiresPermissions("crm:gwgi006:add")
    @RequestMapping("/getAddData")
    @ResponseBody
    public ResponseData getAddData(@DtoParam DtoWapper dtoWapper) {
        Dto outDto = Dtos.newDto();
        ShiroUser shiroUser = ShiroKit.getUser();
        outDto.put("CURRENT_USER_ID", shiroUser.getID());
        outDto.put("CURRENT_USER_NAME", shiroUser.getNAME());
        outDto.put("CURRENT_ORG", shiroUser.getORG_ID());
        outDto.put("CURRENT_ORG_NAME", shiroUser.getSysOrgT().getNAME());
        outDto.put("CURRENT_DATE", LocalDate.now());
        return new SuccessResponseData(outDto);
    }


    @RequiresPermissions("crm:gwgi006:add")
    @RequestMapping("/add")
    @ResponseBody
    public ResponseData add(GwglT gwglT) {
        gwglT.setGWGLENT(ShiroKit.getUser().getDBC());
        gwglTService.add(gwglT);

        return SUCCESS_TIP;
    }

    @RequiresPermissions("crm:gwgi006:edit")
    @RequestMapping("/edit")
    @ResponseBody
    public ResponseData edit(GwglT gwglT) {
        gwglT.setGWGLENT(ShiroKit.getUser().getDBC());

        gwglTService.edit(gwglT);

        return SUCCESS_TIP;
    }

    @RequiresPermissions("crm:gwgi006:del")
    @RequestMapping("/del")
    @ResponseBody
    public ResponseData del(GwglT gwglT) {
        gwglTService.delete(gwglT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("crm:gwgi006:del")
    @RequestMapping("/delBatch")
    @ResponseBody
    public ResponseData delBatch(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwglT> gwglTList = inDto.getReqList(GwglT.class);
        gwglTService.deleteBatch(gwglTList);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("crm:gwgi006:edit")
    @RequestMapping("/changeStatus")
    @ResponseBody
    public ResponseData changeStatus(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<GwglT> gwglTList = inDto.getReqList(GwglT.class);
        Dto outDto = gwglTService.changeStatusBatch(gwglTList);
        if(outDto.getAppCode() == 500) {
            return new ErrorResponseData(500,outDto.getAppMsg());
        }
        return SUCCESS_TIP;
    }

    @RequestMapping("/getBookmarkData")
    @ResponseBody
    public ResponseData getBookmarkData(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        Page page = dtoWapper.getPage();
        List<Dto> gwgiTList = gwglTService.getBookmarkData(page,inDto);
        return new PageReData(page,gwgiTList);
    }

    @RequestMapping("/getGwgc014")
    @ResponseBody
    public ResponseData getGwgc014(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        Dto gwgc014 = gwglTService.getGwgc014(inDto);
        return ResponseData.success(gwgc014);
    }
}
